#include "ui_local.h"
#define SYNC_BUTTON(a, b, c, d) Cmd_RemoveCommand(a); Cmd_RemoveCommand(b); Cmd_AddCommand( a, FindCommandPointer(c) ); Cmd_AddCommand( b, FindCommandPointer(d) );

void *Cmd_AddCommand( const char *name, void *funcptr )
{
	__asm
	{
		mov eax, name
		mov ebx, funcptr
		mov edx, 0x436DA0
		call edx
	}
}

void *Cmd_RemoveCommand( const char *name )
{
	__asm
	{
		mov edx, name
		mov eax, 0x436E30
		call eax
	}
}

// Command lookup
typedef struct jacmd_s
{
	struct jacmd_s *next;
	const char* name;
	void *function;
} jacmd_t;

void *FindCommandPointer( const char *command )
{//Raz - Usage: FindCommandPointer("+buttonX")
	jacmd_t *cmd;
	
	for (cmd = *(jacmd_t **)0xB3CC18; cmd; cmd = cmd->next)
	{
		if ( !Q_stricmp( command, cmd->name ) )
		{
			return cmd->function;
		}
	}
	return NULL;
}

void AM_SyncButtons( void )
{
	SYNC_BUTTON( "+sprint",			"-sprint",			"+button12",		"-button12" );
}